package com.example.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import ch.qos.logback.classic.pattern.MessageConverter;

// 此处为 Rabbitmq 配置类的前置注释区域，后续将定义 RabbitMQ 的队列、交换器和绑定关系。

@Configuration
public class RabbitmqConfig {
    /**
     * 定义支付队列的名称，用于存储支付相关的消息。
     */
    public static final String paymentQueue = "payment.queue";
    /**
     * 定义支付交换器的名称，用于路由支付相关的消息。
     */
    public static final String paymentExchange = "payment.exchange";
    /**
     * 定义支付路由键，用于将消息从交换器路由到对应的队列。
     */
    public static final String paymentRouteKey = "payment.route.key";


    @Bean
    public Queue paymentQueue(){
        return new Queue(paymentQueue,true);
    }


    @Bean
    public DirectExchange paymentExchange(){
        return new DirectExchange(paymentExchange);
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(paymentQueue()).to(paymentExchange()).with(paymentRouteKey);
    }

    /**
     * 比Gson和fastjson好，
     * 1、springboot 默认继承jackson, 通过配置就可以实现序列化和反序列化
     * @return
     */
    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter(){
        return new Jackson2JsonMessageConverter();
    }



}

